package de.uni.muenster.idw2.threads;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import de.uni.muenster.idw2.data.Building;
import de.uni.muenster.idw2.data.Dongle;
import de.uni.muenster.idw2.data.DrawableObject;
import android.R;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;

public class DongleImageLoader extends AsyncTask<Void, Void, Void> {

	private Building building;
	private Activity act;

	public DongleImageLoader(Building building, Activity act){
		this.building = building;
		this.act = act;
		
	}
	
	@Override
	protected void onPreExecute() {
		super.onPreExecute();
	}
	
	@Override
	protected Void doInBackground(Void... params) {
		
		ExecutorService executorService = Executors.newFixedThreadPool(8);
		
		for (int i = 0; i < building.getDongles().size(); i++) {
			Dongle dongle = building.getDongles().get(i);
			
			for (int j = 0; j < dongle.getImageLinks().size(); j++) {
				DrawableObject drawableObject = new DrawableObject(0, null);
				dongle.getImages().add(drawableObject);
				
				DongleLoader dongleLoader = new DongleLoader(drawableObject, dongle.getImageLinks().get(j));
				executorService.execute(dongleLoader);
				
			}
		}
		
		executorService.shutdown();
		while(!executorService.isTerminated()){
			
		}

		return null;
	}
	
	@Override
	protected void onPostExecute(Void result) {
		super.onPostExecute(result);
	}

}
